import Mock from 'mockjs2'
import { builder } from '../util'

const info = options => {
  console.log('options', options)
  const userInfo = {
    id: '4291d7da9005377ec9aec4a71ea837f',
    name: '天野远子',
    username: 'admin',
    password: '',
    avatar: '/avatar2.jpg',
    status: 1,
    telephone: '',
    lastLoginIp: '27.154.74.117',
    lastLoginTime: 1534837621348,
    creatorId: 'admin',
    createTime: 1497160610259,
    merchantCode: 'TLif2btpzg079h15bk',
    deleted: 0,
    roleId: 'admin',
    role: {}
  }
  // role
  const roleObj = {
    id: 'admin',
    name: '管理员',
    describe: '拥有所有权限',
    status: 1,
    creatorId: 'system',
    createTime: 1497160610259,
    deleted: 0,
    permissions: [
      {
        roleId: 'admin',
        permissionId: 'dashboard',
        permissionName: '仪表盘',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'exception',
        permissionName: '异常页面权限',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'result',
        permissionName: '结果权限',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'profile',
        permissionName: '详细页权限',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'table',
        permissionName: '表格权限',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"import","defaultCheck":false,"describe":"导入"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'import',
            describe: '导入',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'form',
        permissionName: '表单权限',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'order',
        permissionName: '订单管理',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'permission',
        permissionName: '权限管理',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'role',
        permissionName: '角色管理',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'table',
        permissionName: '桌子管理',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"query","defaultCheck":false,"describe":"查询"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'query',
            describe: '查询',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      },
      {
        roleId: 'admin',
        permissionId: 'user',
        permissionName: '用户管理',
        // actions:
        //   '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"import","defaultCheck":false,"describe":"导入"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"},{"action":"export","defaultCheck":false,"describe":"导出"}]',
        actionEntitySet: [
          {
            action: 'add',
            describe: '新增',
            defaultCheck: false
          },
          {
            action: 'import',
            describe: '导入',
            defaultCheck: false
          },
          {
            action: 'get',
            describe: '详情',
            defaultCheck: false
          },
          {
            action: 'update',
            describe: '修改',
            defaultCheck: false
          },
          {
            action: 'delete',
            describe: '删除',
            defaultCheck: false
          },
          {
            action: 'export',
            describe: '导出',
            defaultCheck: false
          }
        ],
        actionList: null,
        dataAccess: null
      }
    ]
  }

  // roleObj.permissions.push({
  //   roleId: 'admin',
  //   permissionId: 'support',
  //   permissionName: '超级模块',
  //   actions:
  //     '[{"action":"add","defaultCheck":false,"describe":"新增"},{"action":"import","defaultCheck":false,"describe":"导入"},{"action":"get","defaultCheck":false,"describe":"详情"},{"action":"update","defaultCheck":false,"describe":"修改"},{"action":"delete","defaultCheck":false,"describe":"删除"},{"action":"export","defaultCheck":false,"describe":"导出"}]',
  //   actionEntitySet: [
  //     {
  //       action: 'add',
  //       describe: '新增',
  //       defaultCheck: false
  //     },
  //     {
  //       action: 'import',
  //       describe: '导入',
  //       defaultCheck: false
  //     },
  //     {
  //       action: 'get',
  //       describe: '详情',
  //       defaultCheck: false
  //     },
  //     {
  //       action: 'update',
  //       describe: '修改',
  //       defaultCheck: false
  //     },
  //     {
  //       action: 'delete',
  //       describe: '删除',
  //       defaultCheck: false
  //     },
  //     {
  //       action: 'export',
  //       describe: '导出',
  //       defaultCheck: false
  //     }
  //   ],
  //   actionList: null,
  //   dataAccess: null
  // })

  userInfo.role = roleObj
  return builder(userInfo)
}

/**
 * 使用 用户登录的 token 获取用户有权限的菜单
 * 返回结构必须按照这个结构体形式处理，或根据
 * /src/router/generator-routers.js  文件的菜单结构处理函数对应即可
 * @param {*} options
 * @returns
 */
const userNav = options => {
  const nav = [
    // dashboard
    {
      name: 'dashboard',
      parentId: 0,
      id: 1000,
      meta: {
        icon: 'dashboard',
        title: '仪表盘',
        show: true
      },
      component: 'RouteView',
      redirect: '/dashboard/workplace'
    },
    {
      name: 'workplace',
      parentId: 1000,
      id: 10001,
      meta: {
        title: '工作台',
        show: true
      },
      component: 'dashboard/WorkplaceOne'
    },
    {
      name: 'Analysis',
      parentId: 1000,
      id: 10002,
      meta: {
        title: '分析页',
        show: true
      },
      component: 'dashboard/Analysis',
      path: '/dashboard/analysis'
    },
    {
      name: 'develop',
      parentId: 0,
      id: 1005,
      meta: {
        title: '开发管理',
        icon: 'tool',
        show: true
      },
      redirect: '/develop/parameter',
      component: 'RouteView'
    },
    {
      path: '/develop/parameter',
      name: 'parameter',
      parentId: 1005,
      id: 10051,
      component: 'develop/parameter',
      meta: {
        title: '参数管理',
        hidden: true
      }
    },
    {
      path: '/develop/sms',
      name: 'sms',
      parentId: 1005,
      id: 10052,
      component: 'develop/sms',
      meta: {
        title: '短信管理',
        hidden: true
      }
    },
    {
      name: 'journal',
      parentId: 0,
      id: 1006,
      meta: {
        title: '日志管理',
        icon: 'profile',
        show: true
      },
      redirect: '/journal/access',
      component: 'RouteView'
    },
    {
      path: '/journal/access',
      name: 'access',
      parentId: 1006,
      id: 10061,
      component: 'journal/access',
      meta: {
        title: '访问日志',
        show: true
      }
    },
    {
      path: '/journal/operation',
      name: 'operation',
      parentId: 1006,
      id: 10062,
      component: 'journal/operation',
      meta: {
        title: '操作日志',
        show: true
      }
    },

    // System
    {
      name: 'system',
      parentId: 0,
      id: 1002,
      meta: { icon: 'setting', title: '系统管理', show: true },
      component: 'RouteView',
      redirect: '/system/user'
    },
    {
      name: 'user',
      parentId: 1002,
      id: 10021,
      meta: { 'title': '用户管理', 'show': true },
      component: 'system/user'
    },
    {
      name: 'department',
      parentId: 1002,
      id: 10022,
      meta: { 'title': '部门管理', 'show': true },
      component: 'system/department',
      path: '/system/department'
    },
    {
      name: 'role',
      parentId: 1002,
      id: 10023,
      meta: { 'title': '角色管理', 'show': true },
      component: 'system/role',
      path: '/system/role'
    },
    {
      name: 'menu',
      parentId: 1002,
      id: 10024,
      meta: { 'title': '菜单管理', 'show': true },
      component: 'system/menu',
      path: '/system/menu'
    },
    {
      name: 'test',
      parentId: 0,
      id: 1003,
      meta: { 'icon': 'setting', 'title': '测试', 'show': true },
      component: 'RouteView',
      redirect: '/dashboard/tests'
    },
    {
      name: 'tests',
      parentId: 1003,
      id: 10031,
      meta: { 'title': '测试', 'show': true },
      component: 'dashboard/TestWork',
      path: '/dashboard/tests'
    },
    {
      name: 'forms',
      parentId: 1003,
      id: 10032,
      meta: { 'title': '表单', 'show': true },
      component: 'other/BigForm',
      path: '/other/forms'
    },
    {
      name: 'icons',
      parentId: 1003,
      id: 10033,
      meta: { 'title': '图标', 'show': true },
      component: 'other/IconSelectorView',
      path: '/other/icons'
    },
    {
      name: 'permissions',
      parentId: 1003,
      id: 10034,
      meta: { 'title': '权限', 'show': true },
      component: 'other/PermissionList',
      path: '/other/permissions'
    },
    {
      name: 'roles',
      parentId: 1003,
      id: 10035,
      meta: { 'title': '角色', 'show': true },
      component: 'other/RoleList',
      path: '/other/roles'
    },
    {
      name: 'tables',
      parentId: 1003,
      id: 10036,
      meta: { 'title': '表格', 'show': true },
      component: 'other/TableInnerEditList',
      path: '/other/tables'
    },
    {
      name: 'trees',
      parentId: 1003,
      id: 10037,
      meta: { 'title': '树形', 'show': true },
      component: 'other/TreeList',
      path: '/other/trees'
    },
    {
      name: 'users',
      parentId: 1003,
      id: 10038,
      meta: { 'title': '用户', 'show': true },
      component: 'other/UserList',
      path: '/other/users'
    },
    // 个人设置
    {
      name: 'account',
      parentId: 0,
      id: 1004,
      meta: {
        title: '个人页',
        icon: 'user',
        show: false,
        hideChildren: false
      },
      redirect: '/account/center',
      component: 'RouteView'
    },
    {
      path: '/account/settings',
      name: 'settings',
      parentId: 1004,
      id: 10041,
      component: 'account/settings/Index',
      meta: { title: '个人设置', show: true },
      redirect: '/account/settings/basic',
      hideChildrenInMenu: true
    },
    {
      path: '/account/settings/basic',
      name: 'BasicSettings',
      parentId: 10041,
      id: 100411,
      component: 'account/settings/BasicSetting',
      meta: { title: '基本设置', show: true }
    },
    {
      path: '/account/settings/security',
      name: 'SecuritySettings',
      parentId: 10041,
      id: 100412,
      component: 'account/settings/Security',
      meta: {
        title: '安全设置',
        show: true
      }
    },
    {
      name: 'CustomSettings',
      path: '/account/settings/custom',
      parentId: 10041,
      id: 100413,
      meta: {
        title: '个性化设置',
        show: true
      },
      component: 'account/settings/Custom'
    },
    {
      name: 'NotificationSettings',
      path: '/account/settings/notification',
      parentId: 10041,
      id: 100414,
      meta: {
        title: '新消息通知',
        show: false
      },
      component: 'account/settings/Notification'
    },
     // Exception
    {
      name: 'exception',
      parentId: 0,
      id: 1007,
      meta: {
        title: '异常页',
        icon: 'warning',
        show: true
      },
      redirect: '/exception/403',
      component: 'RouteView'
    },
    {
      name: '403',
      parentId: 1007,
      id: 10071,
      meta: {
        title: '403',
        show: true
      },
      component: 'exception/403'
    },
    {
      name: '404',
      parentId: 1007,
      id: 10072,
      meta: {
        title: '404',
        show: true
      },
      component: 'exception/404'
    },
    {
      name: '500',
      parentId: 1007,
      id: 10073,
      meta: {
        title: '500',
        show: true
      },
      component: 'exception/500'
    },
    {
      name: 'asset',
      parentId: 0,
      id: 1008,
      meta: {
        title: '资产管理',
        icon: 'ditu',
        show: true
      },
      redirect: '/asset/map',
      component: 'RouteView'
    },
    {
      name: 'map',
      parentId: 1008,
      id: 10081,
      meta: {
        title: '资产地图',
        show: true
      },
      component: 'asset/map'
    }

  ]
  const json = builder(nav)
  console.log('json', json)
  return json
}

Mock.mock(/\/mock\/user\/info/, 'get', info)
Mock.mock(/\/mock\/user\/nav/, 'get', userNav)
